package com.power.controller;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestAttribute;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.power.model.pojo.Ganta;
import com.power.model.pojo.Xianlu;
import com.power.service.GantaService;


@RestController
@RequestMapping("/ganta")
public class GantaControll {
 @Autowired
  GantaService gs;
  @RequestMapping("/all")
  public PageInfo<Ganta> selectAll(@RequestParam("pageno")Integer pageno,@RequestParam("pagesize")Integer pagesize){
      List<Ganta> list = gs.selectAll(pageno, pagesize);
      PageInfo<Ganta> pager = new PageInfo<Ganta>(list);
      return pager;
	}
  


  	@RequestMapping("/where")
	public PageInfo<Ganta> selectTitle(@RequestParam("gcode")String gcode,@RequestParam("xlnum")  String xlnum, @RequestParam("isstatus") Integer isstatus,
			@RequestParam("pageno")Integer pageno, @RequestParam("pagesize")Integer pagesize ){

 		List<Ganta> list = gs.selectbh(gcode, xlnum, isstatus,pageno, pagesize);


  		PageInfo<Ganta> pager = new PageInfo<Ganta>(list);
  	      return pager;
	}
	/*
	 * @RequestMapping("/bianh") public List<Ganta> selectTitle(@Param("gcode")
	 * String gcode){ List<Ganta> list = gs.selectbh(gcode); return list; }
	 */
  
  /*添加杆塔编号*/
  @RequestMapping("/add")

	public String addGanta( String gcode, Integer isstatus,String linecode) {
	  Ganta ganta=new Ganta(null, new Date(), gcode, linecode, isstatus, new Date());
		 gs.addGanta(ganta);
		if(ganta.getGid()!=null && ganta.getGid()>0) {
			return "添加成功"+ganta.getGid();
		}else {
			return "添加失败";
		}

	}
  

  @RequestMapping("/update")
  public void updateGantaIsstatus(@RequestParam("isstatus") Integer isstatus,@RequestParam("gid") Integer gid) {
	  gs.updateGantaIsstatus(isstatus, gid);
  }
  @RequestMapping("/updateGanta")
  public void updateGanta(@RequestBody Ganta ganta) {
	  if(ganta.getXianlu()==null||ganta.getXianlu().getId()==null) {
		  ganta.setXianlu(null);
	  }
	  gs.updateGanta(ganta);
  }

  @RequestMapping("/getGantas")
  public List<Ganta> getGantas(){
	  return gs.getGantas();
  }
  @RequestMapping("/getGantaByXlnum")
  public List<Ganta> getGantaByXlnum(String xlnum){
	return gs.getGantaByXlnum(xlnum);  
  }

  @RequestMapping("updateGantas")
  public void updateGantas(@RequestBody Integer ids[]) {
	  gs.updataGatans(ids);
  }
  @RequestMapping("/getNoFenPei")
  public List<Ganta> selectByxlnumAndRuntype(@RequestParam("xlnum")String xlnum){
	  return gs.selectByxlnumAndRuntype(xlnum);
  }
  @RequestMapping("/updateRuntype")
  public void updateRuntype(@RequestParam("gid") Integer gid) {
	  gs.updateRuntype(gid);
  }

}
